<!DOCTYPE html>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<meta name="Description" content="Some of the requirements for your build environment are determined by which version of the source code you plan to compile. See Codenames, Tags, and Build Numbers for a full listing of branches you may choose from. You may also choose to download and …">

<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>Building the System | Android Developers</title>

<!-- STYLESHEETS -->
<link rel="stylesheet"
href="//fonts.googleapis.com/css?family=Roboto:regular,medium,thin,italic,mediumitalic,bold" title="roboto">
<link href="/assets/css/default.css" rel="stylesheet" type="text/css">



<!-- JAVASCRIPT -->
<script src="//www.google.com/jsapi" type="text/javascript"></script>
<script src="/assets/js/android_3p-bundle.js" type="text/javascript"></script>
<script type="text/javascript">
  var toRoot = "/";
  
  var devsite = false;
  
</script>
<script src="/assets/js/docs.js" type="text/javascript"></script>


<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-45455297-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
</head>

<body class="gc-documentation 
  " itemscope itemtype="http://schema.org/Article">
<a name="top"></a>

  
    <!-- Header -->
    <div id="header">
        <div class="wrap" id="header-wrap">
          <div class="col-3 saclogo">
          <a href="/index.html">
            <img src="/assets/images/sac_logo.png"
                srcset="/assets/images/sac_logo@2x.png 2x"
                width="123" height="25" alt="Android Developers" />
          </a>
          </div>
            <ul class="nav-x col-9">
                <li class="source">
                  <a href="/source/index.html" class="selected"
                  >Source</a></li>
                <li class="devices"><a href="/devices/index.html" 
                  >Devices</a></li>
                <li class="accessories"><a href="/accessories/index.html" 
                  >Accessories</a></li>
                <li class="compatibility last"><a href="/compatibility/index.html" 
                  >Compatibility</a></li>
            </ul>
            <!-- New Search -->
            <div class="menu-container">
            <div class="moremenu">
    <div id="more-btn"></div>
  </div>
  <div class="morehover" id="moremenu">
    <div class="top"></div>
    <div class="mid">
      <div class="header">Android Sites</div>
      <ul>
        <li class="active"><a>Android Open Source Project</a></li>
        <li><a href="http://www.android.com">Android.com</a></li>
        <li><a href="http://developer.android.com">Android Developers</a></li>
      </ul>
      <!-- <div class="header">Support</div>
      <ul>
        <li><a href="/support.html">Developer Support</a></li>
      </ul> -->
      <br class="clearfix" />
    </div>
    <div class="bottom"></div>
  </div>

  <div class="search" id="search-container">
    <div class="search-inner">
      <div id="search-btn"></div>
      <div class="left"></div>
      <form onsubmit="return submit_search()">
        <input id="search_autocomplete" type="text" value="" autocomplete="off" name="q"
onfocus="search_focus_changed(this, true)" onblur="search_focus_changed(this, false)"
onkeydown="return search_changed(event, true, '/')"
onkeyup="return search_changed(event, false, '/')" />
      </form>
      <div class="right"></div>
        <a class="close hide">close</a>
        <div class="left"></div>
        <div class="right"></div>
    </div>
  </div>
  <div id="search_filtered_wrapper">
    <div id="search_filtered_div" class="no-display">
        <ul id="search_filtered">
        </ul>
    </div>
  </div>

  </div>
  <!-- /New Search> -->
        </div>
    </div>
    <!-- /Header -->

  <div id="searchResults" class="wrap" style="display:none;">
          <h2 id="searchTitle">Results</h2>
          <div id="leftSearchControl" class="search-control">Loading...</div>
  </div>

  
  
  
    
  <div class="wrap clearfix" id="body-content">
    <div class="col-4" id="side-nav" itemscope itemtype="http://schema.org/SiteNavigationElement">
      <div id="devdoc-nav" class="scroll-pane">
<a class="totop" href="#top" data-g-event="left-nav-top">to top</a>

<!--
    Copyright 2013 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<ul id="nav">
  <li class="nav-section">
    <div class="nav-section-header">
      <a href="/source/index.html">
        <span class="en">Overview</span>
      </a>
    </div>
    <ul>
      <li><a href="/source/code-lines.html">Codelines, Branches, and Releases</a></li>
      <li><a href="/source/build-numbers.html">Codenames, Tags, and Build Numbers</a></li>
      <li><a href="/source/roles.html">Project Roles</a></li>
      <li><a href="/source/brands.html">Brand Guidelines</a></li>
      <li><a href="/source/licenses.html">Licenses</a></li>
      <li><a href="/source/faqs.html">FAQ</a></li>
    </ul>
  </li>


  <li class="nav-section">
      <div class="nav-section-header">
        <a href="/source/building.html">
          <span class="en">Downloading and Building</span>
        </a>
      </div>
       <ul>
        <li><a href="/source/initializing.html">Initializing the Build Environment</a></li>
        <li><a href="/source/downloading.html">Downloading the Source</a></li>
        <li><a href="/source/building-running.html">Building and Running</a></li>
        <li><a href="/source/building-devices.html">Building for Devices</a></li>
        <li><a href="/source/building-kernels.html">Building Kernels</a></li>
        <li><a href="/source/64-bit-builds.html">64-bit Build Instructions</a></li>
        <li><a href="/source/known-issues.html">Known Issues</a></li>
      </ul>
  </li>
  <li class="nav-section">
          <div class="nav-section-header">
            <a href="/source/developing.html">
              <span class="en">Developing</span>
            </a>
          </div>
          <ul>
            <li><a href="/source/using-repo.html">Using Repo</a></li>
            <li><a href="/source/using-eclipse.html">Using Eclipse</a></li>
            <li><a href="/source/git-resources.html">Git Resources</a></li>
          </ul>
  </li>

  <li class="nav-section">
    <div class="nav-section-header">
      <a href="/source/contributing.html">
        <span class="en">Contributing</span>
      </a>
    </div>
       <ul>
        <li><a href="/source/life-of-a-patch.html">Life of a Patch</a>
        <li><a href="/source/submit-patches.html">Submitting Patches</a></li>
        <li><a href="http://android-review.googlesource.com">View Patches</a></li>
        <li><a href="/source/life-of-a-bug.html">Life of a Bug</a></li>
        <li><a href="/source/report-bugs.html">Reporting Bugs</a></li>
        <li><a href="/source/code-style.html">Code Style Guidelines</a></li>
      </ul>
  </li>

  <li class="nav-section">
    <div class="nav-section-header empty">
      <a href="/source/community/index.html">
        <span class="en">Community</span>
      </a>
    </div>
  </li>

</ul>


      </div>
    </div> <!-- end side-nav -->
    <script>
      $(document).ready(function() {
        scrollIntoView("devdoc-nav");
        });
    </script>

  




<div class="col-12" id="doc-col" >


  
    
      
        <h1 itemprop="name" >Building the System</h1>
      
    
  


  
  <div id="jd-content">


    <div class="jd-descr" itemprop="articleBody">
    <!--
    Copyright 2013 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<div id="qv-wrapper">
  <div id="qv">
    <h2>In this document</h2>
    <ol id="auto-toc">
    </ol>
  </div>
</div>

The following instructions to build the Android source tree apply to all branches, including <code>master</code>.

<h2 id="choosing-a-branch">Choosing a Branch</h2>
<p>Some of the requirements for your build environment are determined by which
version of the source code you plan to compile. See
<a href="build-numbers.html">Codenames, Tags, and Build Numbers</a> for a full listing of branches you may
choose from. You may also choose to download and build the latest source code
(called <code>master</code>), in which case you will simply omit the branch specification
when you initialize the repository.</p>
<p>Once you have selected a branch, follow the appropriate instructions below to
set up your build environment.</p>


<p>The basic sequence of build commands is as follows:</p>
<h2 id="initialize">Initialize</h2>
<p>Initialize the environment with the <code>envsetup.sh</code> script. Note
that replacing <code>source</code> with <code>.</code> (a single dot) saves a few characters,
and the short form is more commonly used in documentation.</p>
<pre><code>$ source build/envsetup.sh
</code></pre>
<p>or</p>
<pre><code>$ . build/envsetup.sh
</code></pre>
<h2 id="choose-a-target">Choose a Target</h2>
<p>Choose which target to build with <code>lunch</code>.  The exact configuration can be passed as
an argument. For example, the following command:</p>
<pre><code>$ lunch aosp_arm-eng
</code></pre>
<p>refers to a complete build for the emulator, with all debugging enabled.</p>
<p>If run with no arguments <code>lunch</code> will prompt you to choose a target from the menu. </p>
<p>All build targets take the form <code>BUILD-BUILDTYPE</code>, where the <code>BUILD</code> is a codename
referring to the particular feature combination. Here's a partial list:</p>
<table>
<thead>
<tr>
<th>Build name</th>
<th>Device</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td>aosp_arm</td>
<td>ARM emulator</td>
<td>AOSP, fully configured with all languages, apps, input methods</td>
</tr>
<tr>
<td>aosp_maguro</td>
<td>maguro</td>
<td>AOSP, running on Galaxy Nexus GSM/HSPA+ ("maguro")</td>
</tr>
<tr>
<td>aosp_panda</td>
<td>panda</td>
<td>AOSP, running on PandaBoard ("panda")</td>
</tr>
</tbody>
</table>
<p>and the BUILDTYPE is one of the following:</p>
<table>
<thead>
<tr>
<th>Buildtype</th>
<th>Use</th>
</tr>
</thead>
<tbody>
<tr>
<td>user</td>
<td>limited access; suited for production</td>
</tr>
<tr>
<td>userdebug</td>
<td>like "user" but with root access and debuggability; preferred for debugging</td>
</tr>
<tr>
<td>eng</td>
<td>development configuration with additional debugging tools</td>
</tr>
</tbody>
</table>
<p>For more information about building for and running on actual hardware, see
<a href="building-devices.html">Building for Devices</a>.</p>
<h2 id="build-the-code">Build the Code</h2>
<p>Build everything with <code>make</code>. GNU make can handle parallel
tasks with a <code>-jN</code> argument, and it's common to use a number of
tasks N that's between 1 and 2 times the number of hardware
threads on the computer being used for the build. For example, on a
dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core),
the fastest builds are made with commands between <code>make -j16</code> and
<code>make -j32</code>.</p>
<pre><code>$ make -j4
</code></pre>
<h2 id="run-it">Run It!</h2>
<p>You can either run your build on an emulator or flash it on a device. Please note that you have already selected your build target with <code>lunch</code>, and it is unlikely at best to run on a different target than it was built for.</p>
<h3 id="flash-a-device">Flash a Device</h3>
<p>To flash a device, you will need to use <code>fastboot</code>, which should be included in your path after a successful build. Place the device in fastboot mode either manually by holding the appropriate key combination at boot, or from the shell with</p>
<pre><code>$ adb reboot bootloader
</code></pre>
<p>Once the device is in fastboot mode, run </p>
<pre><code>$ fastboot flashall -w
</code></pre>
<p>The <code>-w</code> option wipes the <code>/data</code> partition on the device; this is useful for your first time flashing a particular device but is otherwise unnecessary.</p>
<p>For more information about building for and running on actual hardware, see
<a href="building-devices.html">Building for Devices.</a></p>
<h3 id="emulate-an-android-device">Emulate an Android Device</h3>
<p>The emulator is added to your path automatically by the build process. To run the emulator, type</p>
<pre><code>$ emulator
</code></pre>
<h2 id="using-ccache">Using ccache</h2>
<p>ccache is a compiler cache for C and C++ that can help make builds faster.
In the root of the source tree, do the following:</p>
<pre><code>$ export USE_CCACHE=1
$ export CCACHE_DIR=/&lt;path_of_your_choice&gt;/.ccache
$ prebuilts/misc/linux-x86/ccache/ccache -M 50G
</code></pre>
<p>The suggested cache size is 50-100G.</p>
<p>On Linux, you can watch ccache being used by doing the following:</p>
<pre><code>$ watch -n1 -d prebuilts/misc/linux-x86/ccache/ccache -s
</code></pre>
<p>On Mac OS, you should replace <code>linux-x86</code> with <code>darwin-x86</code>.</p>
<p>When using Ice Cream Sandwich (4.0.x) or older, you should replace
<code>prebuilts/misc</code> with <code>prebuilt</code>.</p>
<h2 id="troubleshooting-common-build-errors">Troubleshooting Common Build Errors</h2>
<h3 id="wrong-java-version">Wrong Java Version</h3>
<p>If you are attempting to build a version of Android inconsistent with your
version of Java, <code>make</code> will abort with a message such as</p>
<pre><code>************************************************************
You are attempting to build with the incorrect version
of java.

Your version is: WRONG_VERSION.
The correct version is: RIGHT_VERSION.

Please follow the machine setup instructions at
    https://source.android.com/source/download.html
************************************************************
</code></pre>
<p>This may be caused by:</p>
<ul>
<li>
<p>Failing to install the correct JDK as specified in <a href="initializing.html">Initializing the Build Environment</a>.</p>
</li>
<li>
<p>Another JDK previously installed appearing in your path. Prepend the correct JDK to the beginning of your PATH or remove the problematic JDK.</p>
</li>
</ul>
<h3 id="python-version-3">Python Version 3</h3>
<p>Repo is built on particular functionality from Python 2.x and is unfortunately incompatible with Python 3.  In order to use repo, please install Python 2.x:</p>
<pre><code>$ apt-get install python
</code></pre>
<h3 id="case-insensitive-filesystem">Case Insensitive Filesystem</h3>
<p>If you are building on an HFS filesystem on Mac OS, you may encounter an error such as</p>
<pre><code>************************************************************
You are building on a case-insensitive filesystem.
Please move your source tree to a case-sensitive filesystem.
************************************************************
</code></pre>
<p>Please follow the instructions in <a href="initializing.html">Initializing the Build Environment</a> for creating a case-sensitive disk image.</p>
<h3 id="no-usb-permission">No USB Permission</h3>
<p>On most Linux systems, unprivileged users cannot access USB ports by default. If you see a permission denied error, follow the instructions
<a href="initializing.html">Initializing the Build Environment</a> for configuring USB access.  </p>
<p>If adb was already running and cannot connect to the device after
getting those rules set up, it can be killed with <code>adb kill-server</code>.
That will cause adb to restart with the new configuration.</p>

    </div>
      
      <div class="content-footer layout-content-row" 
                    itemscope itemtype="http://schema.org/SiteNavigationElement">
        <div class="layout-content-col col-9" style="padding-top:4px">
          
            <div class="g-plusone" data-size="medium"></div>
          
        </div>
        
        <div class="paging-links layout-content-col col-4">
          
        </div>
        
      </div>
      
      
      

  </div> <!-- end jd-content -->

<div id="footer" class="wrap" >
  <div id="copyright">
    
  Except as noted, this content is 
  licensed under <a href="http://creativecommons.org/licenses/by/2.5/">
  Creative Commons Attribution 2.5</a>. For details and 
  restrictions, see the <a href="/license.html">Content 
  License</a>.
  </div>
    <div id="footerlinks">
    
  <p>
    <a href="/source/index.html">About Android</a>&nbsp;&nbsp;|&nbsp;
    <a href="/source/community/index.html">Community</a>&nbsp;&nbsp;|&nbsp;
    <a href="/legal.html">Legal</a>&nbsp;&nbsp;|&nbsp;
  </p>
  </div>

</div><!-- end doc-content -->

</div> <!-- end body-content --> 






</body>
</html>



